import request from '@/utils/request'



export default {
    //查询全部
    getUserList(searchModel) {
        return request({
            url: '/user/list',
            method: 'get',

            params: {
                pageNo: searchModel.pageNo,
                pageSize: searchModel.pageSize,
                userName: searchModel.userName,
                phone: searchModel.phone,
                sortField: 'id', // 默认按id排序
                sortOrder: 'desc'  // 默认倒序排序
            }
        });
    },
    //新增
    addUser(user) {
        return request({
            url: '/user',
            method: 'post',
            data: user
        });
    },
    //删除
    delleteUser(id) {
        return request({
            url: `/user/${id}`,
            method: 'delete',

        });
    },
    //修改
    updateUser(user) {
        return request({
            url: '/user',
            method: 'put',
            data: user
        });
    },
    //查询  by  id
    getUserById(id) {
        return request({
            url: `/user/${id}`,
            method: 'get',

        });
    },
    saveUser(user) {
        if(user.id==null && user.id==undefined){
        return this.addUser(user);
        }
         return this.updateUser(user);   
       
    },
    

}